home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amoszine 8
/
Amoszine 8 (Disk 1 of 3).adf
/
ARTS
/
MA_Extension_Tutor_Pt2.asc
< prev
next >
Wrap
Text File
|
1998-04-26
|
7KB
|
213 lines
Extension_Tutorial_Part2 (18/7/1995)
-------------------------------------
I hope you've enjoyed the first part of the extension tutorial and
maybe you have made an interesting routine yourself.
If so, feel free to share it with the rest of the AMOS community.
I've decided to move from 'ready to compile' format to a 'cut and insert'
format.
Each new command/function will consist of three parts:
1) Command description.
2) Token description.
3) Any data to be inserted into the extension data area.
4) The routine itself.
To include a routine into the your extension, you have to insert
the token description into the token list and insert the routine at
a free label.
Have fun!
MANUEL ANDRE
ARBEIDERSSTRAAT Nr. 9
2600 BERCHEM
Belgium
Chapter Three.
==============
Accessing Amos system pointers, variables and structures.
---------------------------------------------------------
When Amos is loaded, several libraries are opened and ready for usage.
These can be found in the _wequ.s file.
Also many variables and structures are set up for direct use.
All of these are accessed through address register A5.
A new command will show how to use them...
Az Triangle X1,Y1 To X2,Y2
Draws a triangle starting from X1,Y1 to X1,Y2 to X2,Y2 to X1,Y1
None of the parameters may be ommitted.
Token definition for Az Triangle X1,Y1 To X2,Y2
DC.W L_AZ_TRIANGLE,-1
DC.B "az triangl","e"+$80,"I0,0t0,0",-1
No new data to be inserted into the extension data zone.
Code for Az Triangle X1,Y1 To X2,Y2
L_AZ_TRIANGLE EQU 4
L4 MOVE.L (A3)+,D7 Y2 \
MOVE.L (A3)+,D6 X2 |
MOVE.L (A3)+,D5 Y1 |-> Reversed order !
MOVE.L (A3)+,D4 X1 /
; Push A6 onto the stack, we need this register
MOVE.L A6,-(SP)
MOVE.L T_GFXBASE(A5),A6 for the Graphics library base.
MOVE.L T_RASTPORT(A5),A1 Load A1 with RastPort adress.
MOVE.L A1,D3 RastPort adress in spare reg.
;
;We have received all four coordinates in registers D4 to D7.
;Registers D4 to D7 are a good place to put them, because their contents
;are NOT trashed by the two Gaphics Library calls we are going to use.
;Beware, register A1 will be trashed AFTER every call to Move or Draw, so
;we have to reload it with the RastPort address after each call.
;Instead of fetching this address every time from memory, we store it in a
;spare data register that will not be trashed.
;This will save some precious CPU time...
;Alert minds will also spot that the address register A6 is only loaded
;once with the Graphics library base.
;This is also a, rather risky, technique to speed up things a little bit more.
;Risky, because it is only to be used when you are not calling routines from
;other libraries...
;Offcourse, one could allways try..and die ;-)
;
MOVE.L D4,D0 X1 -> D0
MOVE.L D5,D1 Y1 -> D1
JSR -240(A6) Move(rastp,x,y)(A1,D0,D1)
MOVE.L D4,D0 X1 -> D0
MOVE.L D7,D1 Y2 -> D1
MOVE.L D3,A1 Restore RastPort adress.
JSR -246(A6) Draw(rastp,x,y)(A1,D0,D1)
MOVE.L D6,D0 X2 -> D0
MOVE.L D7,D1 Y2 -> D1
MOVE.L D3,A1 Restore RastPort adress.
JSR -246(A6) Draw(rastp,x,y)(A1,D0,D1)
MOVE.L D4,D0 X1 -> D0
MOVE.L D5,D1 Y1 -> D1
MOVE.L D3,A1 Restore RastPort adress.
JSR -246(A6) Draw(rastp,x,y)(A1,D0,D1)
; Pop our saved value from the stack, else crash!
MOVE.L (SP)+,A6
RTS Amos back in control
A small comment on the RastPort structure.
It is a vital part of the Amiga ® display building blocks when dealing
with most of the graphical operations, such as drawing lines, plotting
points, etc, etc...
Like allmost anything on the Amiga ®, it is organized as a structure of
a certain lenght.
Let's examine some interesting parts of it.
STRUCTURE RastPort,0 Hey, a structure!
;Not interested at this time, sorry...
LONG rp_Layer
;Contains the pointer to it's BitMap, containing amongst other things, the
;actual displayed memory.
LONG rp_BitMap
;Contains the address that points to the pattern that will be used when filling
;area's of the screen.
LONG rp_AreaPtrn
;Contains the address that points to our temporary RastPort.
;See the Set Tempras command.
LONG rp_TmpRas
;Not interested at this time, sorry...
LONG rp_AreaInfo
;Not interested at this time, sorry...
LONG rp_GelsInfo
;This one is only 1 byte wide and holds which bitplanes of this rp_BitMap
;are to be updated, depending on the colour you're drawing with.
;Each bit represents a bitplane and is selected when set.
;It is normally set to $FF (all bitplanes).
BYTE rp_Mask
;The foreground pen (colour).
BYTE rp_FgPen
;The background pen (colour).
BYTE rp_BgPen
;The outline pen when doing areafills (colour).
BYTE rp_AOLPen
;The drawmode : 0 = JAM1 , 1 = JAM2 , 2 = COMPLEMENT , 4 = INVERSED
BYTE rp_DrawMode
;Not interested at this time, sorry...
BYTE rp_AreaPtSz
;Not interested at this time, sorry...
BYTE rp_linpatcnt
;Just included for boundary reasons...
BYTE rp_Dummy
;Not interested at this time, sorry...
WORD rp_Flags
;16 bit pattern to be used when drawing lines.
WORD rp_LinePtrn
;The X-coordinate of our graphical cursor.
WORD rp_cp_x
;The Y-coordinate of our graphical cursor.
WORD rp_cp_y
;Not interested at this time, sorry... \
STRUCT rp_minterms,8 |
WORD rp_PenWidth |
WORD rp_PenHeight |
LONG rp_Font |
BYTE rp_AlgoStyle |
BYTE rp_TxFlags |
WORD rp_TxHeight |
WORD rp_TxWidth |
WORD rp_TxBaseline |
WORD rp_TxSpacing |
APTR rp_RP_User |
STRUCT rp_longreserved,8 |
ifnd GFX_RASTPORT_1_2 |
STRUCT rp_wordreserved,14 |
STRUCT rp_reserved,8 |
endc /
;Defines the lenght of the rastport structure.
LABEL rp_SIZEOF
Hmm, very interesting, but how to access all this fields by name?
You'll have to 'include' the definition of a rastport into you program.
Where do we find this file?
If you are using one of the commercial assemblers, it is very likely
that you will find it here... INCLUDE:Graphics/rastport.i
So...where does this leave us now???
We are going to make our triangle command even faster!!!
Instead of using the graphics.library Move function, which updates the
rp_cp_x and rp_cp_y values, we are going to poke them ourselves.
Just replace the JSR -$240(A6) line with MOVEM.W D4-5,rp_cp_x(A1)
and remove the two MOVE.L's...
MOVEM.W ???? Means : MOVE Multiple Words (16 bit)
D4-5 ???? Means : register D4 and D5
Another example :
MOVEM.L D0-3/D5/D7,-(SP)
MOVEM.L Means : MOVE Multiple Longwords (32 bit)
D0-3/D5/D7 Means : registers D0 to D3, skip D4, move D5, skip D6, move D7.
I know, poking directly into the rastport structure doesn't sound to be
very legal, but it works...
Some OS fanatics will shoot you for doing this, because your code is no longer
fully compatible with newer versions of the graphics.library to come.
But one could wait forever... So if you want the extra speed, shoot the
OS fanatics!
I hope you enjoyed the second part of this tutorial and if you would like
to see a special topic to be covered in one of the following tutorials...
Drop me a letter.
Happy programming.
Manuel.